package com.huifer.wgx.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * <p>Title : ProjectEntity </p>
 * <p>Description : </p>
 *
 * @author huifer
 * @date 2019-03-20
 */
@Entity
@Table(name = "t_project", schema = "at15", catalog = "")
public class ProjectEntity {

    private Long projectId;
    private String projectName;
    private Timestamp projectStartTime;
    private Timestamp projectEndTime;
    private Integer projectExecutionTime;
    private Integer projectScheduledTime;
    private Long personnelId;
    private PersonnelEntity tPersonnelByPersonnelId;
    private Collection<WorkEntity> tWorksByProjectId;

    @Id
    @Column(name = "project_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }

    @Basic
    @Column(name = "project_name")
    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    @Basic
    @Column(name = "project_start_time")
    public Timestamp getProjectStartTime() {
        return projectStartTime;
    }

    public void setProjectStartTime(Timestamp projectStartTime) {
        this.projectStartTime = projectStartTime;
    }

    @Basic
    @Column(name = "project_end_time")
    public Timestamp getProjectEndTime() {
        return projectEndTime;
    }

    public void setProjectEndTime(Timestamp projectEndTime) {
        this.projectEndTime = projectEndTime;
    }

    @Basic
    @Column(name = "project_execution_time")
    public Integer getProjectExecutionTime() {
        return projectExecutionTime;
    }

    public void setProjectExecutionTime(Integer projectExecutionTime) {
        this.projectExecutionTime = projectExecutionTime;
    }

    @Basic
    @Column(name = "project_scheduled_time")
    public Integer getProjectScheduledTime() {
        return projectScheduledTime;
    }

    public void setProjectScheduledTime(Integer projectScheduledTime) {
        this.projectScheduledTime = projectScheduledTime;
    }

    @Basic
    @Column(name = "personnel_id")
    public Long getPersonnelId() {
        return personnelId;
    }

    public void setPersonnelId(Long personnelId) {
        this.personnelId = personnelId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ProjectEntity that = (ProjectEntity) o;
        return Objects.equals(projectId, that.projectId) &&
                Objects.equals(projectName, that.projectName) &&
                Objects.equals(projectStartTime, that.projectStartTime) &&
                Objects.equals(projectEndTime, that.projectEndTime) &&
                Objects.equals(projectExecutionTime, that.projectExecutionTime) &&
                Objects.equals(projectScheduledTime, that.projectScheduledTime) &&
                Objects.equals(personnelId, that.personnelId);
    }

    @Override
    public int hashCode() {
        return Objects
                .hash(projectId, projectName, projectStartTime, projectEndTime,
                        projectExecutionTime,
                        projectScheduledTime, personnelId);
    }

    @ManyToOne
    @JoinColumn(name = "personnel_id", referencedColumnName = "personnel_id",insertable = false,updatable = false)
    public PersonnelEntity gettPersonnelByPersonnelId() {
        return tPersonnelByPersonnelId;
    }

    public void settPersonnelByPersonnelId(PersonnelEntity tPersonnelByPersonnelId) {
        this.tPersonnelByPersonnelId = tPersonnelByPersonnelId;
    }

    @OneToMany(mappedBy = "tProjectByProjectId")
    @JsonIgnore
    public Collection<WorkEntity> gettWorksByProjectId() {
        return tWorksByProjectId;
    }

    public void settWorksByProjectId(Collection<WorkEntity> tWorksByProjectId) {
        this.tWorksByProjectId = tWorksByProjectId;
    }
}
